package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;

/**
 * @author: wf
 * @create: 2025/5/8 14:34
 * @description:
 */

@Component
public class ExecutorXxJob {
    
    /**
     * 跨平台http请求任务(GET请求)
     * @throws Exception
     */
    @XxlJob("igetcoolJobHandler")
    public void igetcoolJobHandler() throws Exception {
        //XxlJobHelper.handleFail();
        XxlJobHelper.handleSuccess("执行成功！！！");
        XxlJobHelper.log("yyyy-MM-dd HH:mm:ss", "打印日志数据1111111111111");
        System.out.println("11111111111111");
        
        StackTraceElement callInfo = new Throwable().getStackTrace()[0];
        System.out.println(callInfo.getClassName());
        System.out.println(callInfo.getMethodName());
        System.out.println(callInfo.getLineNumber());
        System.out.println("========================================");
        
        
 /*       // param parse
        String param = XxlJobHelper.getJobParam();
        if (param==null || param.trim().length()==0) {
            XxlJobHelper.log("param["+ param +"] invalid.");
            XxlJobHelper.handleFail();
            return;
        }
        //get request url
        String url = param.trim();
        // request
        HttpURLConnection connection = null;
        BufferedReader bufferedReader = null;
        try {
            // connection
            URL realUrl = new URL(url);
            connection = (HttpURLConnection) realUrl.openConnection();
            
            // connection setting
            connection.setRequestMethod("GET");
            connection.setDoInput(true);
            connection.setUseCaches(false);
            connection.setReadTimeout(5 * 1000);
            connection.setConnectTimeout(3 * 1000);
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
            connection.setRequestProperty("Accept-Charset", "application/json;charset=UTF-8");
            
            // do connection
            connection.connect();
            
            // valid StatusCode
            int statusCode = connection.getResponseCode();
            if (statusCode != 200) {
                throw new RuntimeException("Http Request StatusCode(" + statusCode + ") Invalid.");
            }
            
            // result
            bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
            StringBuilder result = new StringBuilder();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                result.append(line);
            }
            String responseMsg = result.toString();
            
            XxlJobHelper.log(responseMsg);
            return;
        } catch (Exception e) {
            XxlJobHelper.log(e);
            XxlJobHelper.handleFail();
            return;
        } finally {
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
                if (connection != null) {
                    connection.disconnect();
                }
            } catch (Exception e2) {
                XxlJobHelper.log(e2);
            }
        }*/
    }
}
